﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sy4_7
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        // 窗体加载事件：初始化背景、火箭和进度条
        private void Form1_Load(object sender, EventArgs e)
        {
            LoadBackground();
            InitRocket();
            InitProgress();
        }

        // 初始化发射场背景
        private void LoadBackground()
        {
            Bitmap backPic = new Bitmap("发射场.jpg");
            this.BackgroundImage = backPic;
            this.ClientSize = new Size(backPic.Width, backPic.Height);
        }

        // 初始化火箭图像框
        private void InitRocket()
        {
            Bitmap rocketPic = new Bitmap("火箭.gif");
            pictureBox1.Image = rocketPic;
            pictureBox1.BackColor = Color.Transparent; // 背景透明
            pictureBox1.ClientSize = new Size(rocketPic.Width, rocketPic.Height);
            // 火箭初始位置：水平居中，垂直隐藏底部喷射部分
            pictureBox1.Left = this.ClientSize.Width / 2 - pictureBox1.Width / 2;
            pictureBox1.Top = this.ClientSize.Height - pictureBox1.Height + 100;
        }

        // 初始化进度条
        private void InitProgress()
        {
            progressBar1.Dock = DockStyle.Top;
            progressBar1.Maximum = pictureBox1.Top + pictureBox1.Height; // 进度条最大值为火箭移动总距离
            progressBar1.Minimum = 0;
            progressBar1.Value = 0;
        }

        // 窗体双击事件：启动火箭发射动画
        private void Form1_DoubleClick(object sender, EventArgs e)
        {
            timer1.Enabled = true; // 启动时钟，开始动画
        }

        // 时钟 Tick 事件：控制火箭上升和进度条滚动
        private void Timer1_Tick(object sender, EventArgs e)
        {
            pictureBox1.Top--; // 火箭上升（Top值减小）
            progressBar1.Value++; // 进度条前进

            // 火箭飞出窗体时，停止动画
            if (progressBar1.Value >= progressBar1.Maximum)
            {
                timer1.Enabled = false;
            }
        }
    }
}
